﻿@{
    ViewBag.Title = "财务对账审核";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}
@section scripts{
    <script src="~/Scripts/jquery.AnkeExtend.js"> </script>
    <script type="text/javascript">
        var Materials = new Array();
        //页面动态改动
        $(window).resize(function () {
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");
        });

        //页面初始化
        $(document).ready(function () {
            DisableBackspace();
            $('#txtStartTime').datetimebox("setValue", $.GetToday1());  //默认取昨天。
            $('#txtEndTime').datetimebox("setValue", $.GetToday());  //默认取今天现在。

            //#region 为Combobox增加--请选择--
            function EUIcombobox(jqS, o) {
                $.ajax({
                    type: "POST",
                    async: false,
                    url: o.url,
                    dataType: "JSON",
                    success: function (data1, textStatus, jqXHR) {
                        o.data = o.OneOption.concat(data1);
                        delete o.url;
                        delete o.OneOption;
                        $(jqS).combobox(o);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert("获取字典数据失败！可能是已经超时，请重新登录！");
                    }
                });
            }
            //#endregion

            //#region 分中心
            EUIcombobox("#txtCenter", {
                url: '@Url.Content("~/Medical/GetCenter/")',
                valueField: 'ID',
                textField: 'Name',
                //prompt: '--请选择--',
                //editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }],
                onSelect: function (rec) {
                    var urlstation = '@Url.Content("~/Medical/GetStation?code=")' + rec.ID;
                    EUIcombobox("#txtStation", {
                        url: urlstation,
                        valueField: 'ID',
                        textField: 'Name',
                        //prompt: '--请选择--',
                        editable: false,
                        OneOption: [{
                            ID: "",
                            Name: "--请选择--"
                        }]
                    });
                }
            });
            //#endregion

            //#region 出车分站
            EUIcombobox("#txtStation", {
                url: '@Url.Content("~/Medical/GetStation?code=")',
                valueField: 'ID',
                textField: 'Name',
                //prompt: '--请选择--',
                editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });
            //#endregion

            //bindGrid();
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");
        })

        function bindGrid() {
            $('#grid').datagrid({
                loadMsg: '数据加载中,请稍后……',
                url: '@Url.Content("~/DD/DriverReport/GetTaskChargeDetail")',
                height: 440,
                fitColumns: false, //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
                singleSelect: false,
                selectOnCheck: true, //如果为true，单击复选框将永远选择行。
                checkOnSelect: true,  //如果为true，当用户点击行的时候该复选框就会被选中或取消选中。
                striped: true,
                showFooter: true,
                rownumbers: true,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
                queryParams: {
                    StartTime: $("#txtStartTime").datetimebox('getValue'),
                    EndTime: $("#txtEndTime").datetimebox('getValue'),
                    Center: $("#txtCenter").combobox('getValue'),
                    Station: $("#txtStation").combobox('getValue'),
                    IfCheck: $("#txtIfCheck").combobox('getValue'),
                    InvoiceNumber: $("#txtInvoiceNumber").textbox('getValue'),
                    OutTradeNo: $("#txtOutTradeNo").textbox('getValue'),
                    PatientName: $("#txtPatientName").textbox('getValue')
                    //paytype: '@ViewData["payType"]'//支付宝或微信
                },
                columns: [[
                    { field: "ID", hidden: true },
                    { field: "ck", checkbox: true },
                    { field: "CenterName", title: "分中心", width: '5%', align: "center", sortable: false, resizable: false },
                    { field: "StationName", title: "分站", width: '6%', align: "center", sortable: false, resizable: false },
                    { field: "ChargeTime", title: "收费时间", width: '10%', align: "center" },
                    { field: "InvoiceNumber", title: "发票号", width: '9%', align: "center" },
                    { field: "PatientName", title: "病人姓名", width: '5%', align: "center" },
                    { field: "Driver", title: "司机", width: '5%', align: "center" },
                    { field: "ReceivableTotal", title: "应收", width: '5%', align: "center" },
                    { field: "PaidCarFee", title: "车费实收", width: '5%', align: "center" },
                    { field: "PaidPRFee", title: "医疗费实收", width: '6%', align: "center" },
                    { field: "PaidMoney", title: "实收", width: '5%', align: "center" },
                    {
                        field: "RecordMoney", title: "平台实收", width: '8%', align: "center",
                        styler: function (value, row, index) {
                            if (value != row.PaidMoney) {
                                return 'background-color:#BCF8C5;color:red;';
                            }
                        }
                    },
                    { field: "ChargeType", title: "收费方式", width: '5%', align: "center",hidden:true },
                    { field: "OutTradeNo", title: "商户订单号", width: '14%', align: "center" },
                    {
                        field: "IFAccountCheck", title: "财务审核", width: '7%', align: "center",
                        formatter: function (value, row, index) {
                            if (row.StationName == "合计")
                            { return ""; }
                            if (value) {
                                return value;
                            } else {
                                return '<a  id="toggleCheckID" class="linkToggle" onclick="ToggleRowSubmit(\'' + row.ID + '\');"  href="javascript:void(0)"></a>';
                            }
                        }
                    }]],
                toolbar: [
                 {
                     id: 'btnCheck',
                     text: '批量审核',
                     iconCls: 'icon-custom-cGoods',
                     iconWidth: 22,
                     handler: function () {
                         if (Materials.length > 0) {
                             submitBatchForm(); //批量审核
                         } else {
                             $.messager.alert('系统提示', '请勾选需要审核的行', 'info', function () {
                             });
                         }
                     }
                 }
                ],
                onCheck: function (index, row) {
                    if (Materials.length == 0) {
                        Materials.push(row);
                        //changeRevisitViewNum();
                        return;
                    }
                    var boolContain = false;
                    $.each(Materials, function (i, info) {
                        if (info.ID == row.ID) {
                            boolContain = true;
                        }
                    });
                    if (!boolContain) {
                        Materials.push(row);
                    }
                    //changeRevisitViewNum();

                },
                onUncheck: function (index, row) {
                    var obj;
                    $.each(Materials, function (i, info) {
                        if (info.ID == row.ID) {
                            obj = info;
                        }
                    });
                    Materials.remove(obj);
                    //changeRevisitViewNum();
                },
                onCheckAll: function (rows) {
                    $.each(rows, function (i, infos) {
                        // var arr = ["xml", "html", "css", "js"];
                        //   $.inArray("js", arr);  //返回 3,
                        //  如果不包含在数组中, 则返回 - 1;

                        var hasmates = false;
                        $.each(Materials, function (index, mates) {
                            if (infos.ID == mates.ID) {
                                hasmates = true;
                            }
                        });
                        // if (Materials.indexOf(rows[ii]) < 0) {  //index用法只能用于string之间，不可以用于数组。
                        if (!hasmates)
                        { Materials.push(infos); }
                    }
                    );
                    //changeRevisitViewNum();
                },
                onUncheckAll: function (rows) {
                    var obj;
                    $.each(rows, function (i, infos) {
                        $.each(Materials, function (index, mates) {
                            if (infos.ID == mates.ID) {
                                //if ($.inArray(rows[i], Materials)>=0){
                                obj = infos;
                            }
                        });
                        Materials.remove(obj);

                        //changeRevisitViewNum();
                    });
                },
                onLoadSuccess: function (data) {
                    $('.linkSP').linkbutton({
                        text: '撤销',
                        plain: true,
                        iconCls: 'icon-custom-cJinYong'
                    });
                    $('.linkToggle').linkbutton({
                        text: '审核',
                        plain: true,
                        iconCls: 'icon-add',
                        toggle: true
                    });
                //    //新增合计行
                //    $('#grid').datagrid('appendRow', {
                //        CenterName: '<span class="subtotal">合计</span>',
                //        PaidMoney: '<span class="subtotal">' + compute("PaidMoney") + '</span>',
                    //    });
                    $('#grid').datagrid('fixRowHeight');//解决行号错位
                }
            });
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");
        }

        //合计
        //function compute(colName) {
        //    var rows = $('#grid').datagrid('getRows');
        //    var total = 0;
        //    for (var i = 0; i < rows.length; i++) {
        //        total += parseFloat(rows[i][colName]);
        //    }
        //    return total;
        //}

        //查询
        function reSearch() {
            bindGrid();

            //$('#grid').datagrid({
            //    pageNumber: 1,//点击查询返回第一页
            //    queryParams: {
            //        StartTime: $("#txtStartTime").datetimebox('getValue'),
            //        EndTime: $("#txtEndTime").datetimebox('getValue'),
            //        Center: $("#txtCenter").combobox('getValue'),
            //        Station: $("#txtStation").combobox('getValue'),
            //        IfCheck: $("#txtIfCheck").combobox('getValue'),
            //        InvoiceNumber: $("#txtInvoiceNumber").textbox('getValue'),
            //        OutTradeNo: $("#txtOutTradeNo").textbox('getValue'),
            //        PatientName: $("#txtPatientName").textbox('getValue')
            //    }
            //})
        }

        //财务单个审核
        function ToggleRowSubmit(rowCheckID) {
            document.getElementById('toggleCheckID').disabled = true;
            //审核提交
            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/DD/DriverReport/SavaCheck")',
                data:
                    {
                        taskcode: rowCheckID
                    },
                dataType: "json",
                success: function (jsData) {
                    $("#grid").datagrid("reload");

                    $.handleJsonResult(jsData, function () {
                        document.getElementById('toggleCheckID').disabled = false;
                    });
                }
            });
        };

        //批量审核
        function submitBatchForm() {

            $.messager.confirm('提示', '确认批量审核吗?', function (r) {
                if (r) {
                    var jsData = new Array();
                    var i = 0;
                    var rows = $('#grid').datagrid('getChecked');

                    $(rows).each(function () {
                        var obj = new Object();
                        obj.ID = rows[i].ID;
                        obj.IFAccountCheck = "已审核";
                        jsData.push(obj);
                        i++;
                    });

                    $.ajax({
                        type: 'POST',
                        url: '@Url.Content("~/DD/DriverReport/SavaBatchCheck")',
                        data:
                            {
                                sDeliveryDetailInfo: JSON.stringify(jsData)
                            },
                        dataType: "json",
                        success: function (jsData) {
                            $.handleJsonResult(jsData, function () {
                                Materials.length = 0;
                                $("#grid").datagrid("reload");
                            });
                        }
                    });
                }
                else {

                }
            })
        }

    </script>
}
<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'财务对账审核',iconCls:'icon-custom-Entry'">
        <div id="SearchBar" data-options="region:'center'" style="overflow: hidden; padding: 10px">
            <table style="width:99%" cellpadding="0" cellspacing="5" border="0">
                <tr>
                    <td align="right" valign="middle" width="8%">查询时间：</td>
                    <td align="left" valign="middle" width="13%">
                        <input class="easyui-datetimebox" style="width:140px" id="txtStartTime">
                    </td>
                    <td align="right" valign="middle" width="8%">至：</td>
                    <td align="left" valign="middle" width="13%">
                        <input class="easyui-datetimebox" style="width:140px" id="txtEndTime">
                    </td>
                    <td align="right" valign="middle" width="6%">
                        分中心：
                    </td>
                    <td>  <input class="easyui-combobox" style="width:140px" id="txtCenter" data-options="editable:false"></td>

                    <td align="right" valign="middle" width="6%">
                        分站：
                    </td>
                    <td>  <input class="easyui-combobox" style="width:140px" id="txtStation" data-options="editable:false"></td>
                </tr>
                <tr>
                    <td align="right" valign="middle" width="6%">
                        发票号：
                    </td>
                    <td>  <input class="easyui-textbox" style="width:140px" id="txtInvoiceNumber"></td>
                    <td align="right" valign="middle" width="6%">
                        病人姓名：
                    </td>
                    <td>  <input class="easyui-textbox" style="width:140px" id="txtPatientName"></td>
                    <td align="right" valign="middle" width="8%">
                        商户订单号：
                    </td>
                    <td>  <input class="easyui-textbox" style="width:140px" id="txtOutTradeNo"></td>
                    <td align="right" valign="middle" width="6%">
                        是否审核：
                    </td>
                    <td align="right" valign="middle" width="12%">
                        <select class="easyui-combobox" style="width: 140px" id="txtIfCheck" data-options="panelHeight:'auto', editable:false">
                            <option value="-1">--请选择--</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </td>
                    <td width="12%">
                        &nbsp;&nbsp;
                        <a href="javascript:void(0)" id="btnStationsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reSearch()">查询</a>
                    </td>
                </tr>
            </table>
        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="grid"></table>
        </div>
    </div>
</div>


